package com.hns.can.common.aop.sedate;


import java.util.List;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hns.can.common.service.SedateService;
import com.hns.frame.enumrate.MsgType;
import com.hns.frame.exception.BusinessException;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.SearchConditionVo;

/**
 * 左侧树选择多项放临时表关联
 * @author wuchaoxing
 *
 */
@Aspect
@Component
public class SedateAop {

	private final Logger logger = LoggerFactory.getLogger(SedateAop.class); 
	
	@Autowired
	public SedateService sedateService;

	public SedateAop() {
		logger.debug("LeftOrgRelAop start");
	}
	
	/**
	 * 
	 * @param point
	 * @param sedateAnnotation
	 * @author:Qianjy
	 * @email:494758538@qq.com
	 * @创建日期:2016-5-24
	 * @功能说明：插入开始结束时间至临时表面向AOP
	 */
	@SuppressWarnings("unchecked")
	@Before("execution(* *.*(..)) && @annotation(sedateAnnotation)")
	public void insertLeftTreeTab(JoinPoint point, SedateAnnotation sedateAnnotation) {
		Object[] object = point.getArgs();
		if(object.length < 1)
			throw new BusinessException(MsgType.ERROR.getFlag(), "参数个数不对！");
		
		Object objectIds = object[0];
		if(!(objectIds instanceof List<?> || objectIds instanceof SearchConditionVo))
			throw new BusinessException(MsgType.ERROR.getFlag(), "参数List不是机构ID！");
		
		if(PubUtil.isEmpty(objectIds))
			return;
		
		SearchConditionVo searchConditionVo = null;
		if(object[0] instanceof SearchConditionVo){
		    searchConditionVo = ((SearchConditionVo)object[0]);
		}
		if(PubUtil.isEmpty(searchConditionVo))
			return;
		
		//新增插入包体开始时间和结束时间
		sedateService.setOracleSessionSeDate(searchConditionVo);
	}
	
}
